package com.shadow.mall.order.remote.dubbo;

import com.alibaba.csp.sentinel.annotation.SentinelResource;

import com.shadow.mall.common.core.JsonResult;
import com.shadow.mall.inventory.api.InventoryApi;
import com.shadow.mall.inventory.domain.request.DeductProductStockRequest;
import com.shadow.mall.order.exception.OrderBizException;
import com.shadow.mall.order.remote.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 库存服务远程接口
 * 
 * @version 1.0
 */
@Component
public class InventoryRemote {

    /**
     * 库存服务
     * dubbo
     */

//    private InventoryApi inventoryApi;

    @Autowired
    private InventoryService inventoryService;

    /**
     * 扣减订单条目库存
     * @param lockProductStockRequest
     */
    @SentinelResource(value = "InventoryRemote:deductProductStock")
    public void deductProductStock(DeductProductStockRequest lockProductStockRequest) {
        JsonResult<Boolean> jsonResult = inventoryService.deductProductStock(lockProductStockRequest);
        // 检查锁定商品库存结果
        if (!jsonResult.getSuccess()) {
            throw new OrderBizException(jsonResult.getErrorCode(), jsonResult.getErrorMessage());
        }
    }
}